﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Data.SqlClient;
using System.Configuration;

public partial class Register : System.Web.UI.Page
{
    string sqlconnstr = ConfigurationManager.ConnectionStrings["ConnectionString"].ToString();
    SqlConnection sqlconn;
    SqlDataAdapter sqld;
    DataSet ds = new DataSet();
    protected void Page_Load(object sender, EventArgs e)
    {
        
    }
    protected void Button1_Click(object sender, EventArgs e)
    {
        string strsql1 = "select * from Teacher where TeacherID='" + TextBox1.Text.Trim() + "'";
        sqlconn = new SqlConnection(sqlconnstr);
        sqld = new SqlDataAdapter(strsql1, sqlconn);
        sqld.Fill(ds, "tabteacher");
        if (ds.Tables["tabteacher"].Rows.Count > 0)
        {
            Response.Write("<script>alert('该老师已经注册！');location='javascript:history.go(-1)'</script>");
            return;
        }
        string sqlstr = "insert into Teacher(TeacherID,TeacherName,PassWord,Sex,Email)values('" + TextBox1.Text.Trim() + "','" + TextBox2.Text.Trim() + "','" + TextBox3.Text.Trim() + "','" + DropDownList1.Text.Trim() + "','" + TextBox5.Text.Trim() + "')";

        SqlCommand sqlcomm;
        try
        {
            sqlconn.Open();
            sqlcomm = new SqlCommand(sqlstr, sqlconn);
            sqlcomm.ExecuteNonQuery();
        }
        catch (Exception ex)
        {
            Response.Write(ex.Message);
        }
        finally
        {
            sqlconn.Close();
            sqlconn = null;
            sqlcomm = null;
            Response.Write("<script>alert('注册成功！');location='Login.aspx';</script>");
        }
    }
    protected void Button2_Click(object sender, EventArgs e)
    {
        TextBox1.Text = "";
        TextBox2.Text = "";
        TextBox3.Text = "";
        TextBox4.Text = "";
        TextBox5.Text = "";
        DropDownList1.SelectedIndex = -1;
    }
}